/**
 *
 */
package com.tl.commonlibrary.tool;

import android.text.TextUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

/**
 * 
 * @note：时间日期帮助类
 * @author wangyd
 * @date:2008-2-23
 */
public class DateUtil {

    public static final String DATE_FORMAT = "yyyy-MM-dd";

    public DateUtil() {
    }

	/**
	 * 
	 * TODO:取当前年份
	 * 
	 * @return:
	 */
	@SuppressWarnings("static-access")
	public static int getCurrentYear() {
		Calendar calendar = Calendar.getInstance();
		Date currentDate = new Date();
		calendar.setTime(currentDate);
		return calendar.get(calendar.YEAR);
	}

	/**
	 * 
	 * TODO:取当前月份
	 * 
	 * @return:
	 */
	@SuppressWarnings("static-access")
	public static int getCurrentMonth() {
		Calendar calendar = Calendar.getInstance();
		Date currentDate = new Date();
		calendar.setTime(currentDate);
		return calendar.get(calendar.MONTH) + 1;
	}

	/**
	 * 
	 * TODO:取当前日期的天
	 * 
	 * @return:
	 */
	public static int getCurrentDay() {
		Calendar calendar = Calendar.getInstance();
		Date currentDate = new Date();
		calendar.setTime(currentDate);

		return calendar.get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * 获取某个日期的天数 TODO:
	 * 
	 * @param date
	 * @return:
	 * @date:2011-3-19 下午03:19:15
	 * @author:Dane.wang
	 */
	public static int getDay(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * 
	 * TODO:取当前日期的小时
	 * 
	 * @return:
	 */
	public static int getCurrentHour() {
		Calendar calendar = Calendar.getInstance();
		Date currentDate = new Date();
		calendar.setTime(currentDate);
		return calendar.get(Calendar.HOUR_OF_DAY);
	}

	/**
	 * 
	 * TODO:取当前日期的分钟
	 * 
	 * @return:
	 */
	public static int getCurrentMinute() {
		Calendar calendar = Calendar.getInstance();
		Date currentDate = new Date();
		calendar.setTime(currentDate);

		return calendar.get(Calendar.MINUTE);
	}

	/**
	 * 
	 * TODO:
	 * 
	 * @param date
	 *            待转换的日期
	 * @param pattern
	 *            需要转换后的格式 yyyy-MM-dd 、yyyy-MM-dd hh:mm:ss等格式
	 * @return:
	 */
	public static String formatDateToString(Date date, String pattern) {
		if (date == null) {
			return "";
		}
		if (pattern == null || pattern.equals("")) {
			pattern = "yyyy-MM-dd";
		}
		SimpleDateFormat formatDate = new SimpleDateFormat(pattern);
		return formatDate.format(date);
	}

	/**
	 * 
	 * TODO:将字符串日期转换为日期对象
	 * 
	 * @param dateStr
	 *            待转换的日期
	 * @return:
	 */
	public static Date formateDateToString(String dateStr) {
		if (dateStr == null || dateStr.equals("")) {
			return null;
		}
		dateStr = dateStr.trim();
		try {
			if (dateStr.length() <= 10) {
				dateStr += " 00:00";
			}
			SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			Date returnDate = formatDate.parse(dateStr);
			return returnDate;

		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 
	 * TODO:将字符串日期转换为日期对象
	 * 
	 * @param dateStr
	 *            待转换的日期
	 * @return:
	 */
	public static Date formateDateToStr(String dateStr) {
		if (dateStr == null || dateStr.equals("")) {
			return null;
		}
		dateStr = dateStr.trim();
		try {
			SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
			Date returnDate = formatDate.parse(dateStr);
			return returnDate;

		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 日期比较
	 * 
	 * @author zhangmx
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static int compareDate(String date1, String date2) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date dt1 = df.parse(date1);
			Date dt2 = df.parse(date2);
			if (dt1.getTime() > dt2.getTime()) {
				return 1;
			} else if (dt1.getTime() < dt2.getTime()) {
				return -1;
			} else {
				return 0;
			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return 0;
	}
	public static int compareDate(String DATE1, String DATE2, String DateFormat) {
		java.text.DateFormat df = new SimpleDateFormat(DateFormat, Locale.CHINA);
		try {
			Date dt1 = df.parse(DATE1);
			Date dt2 = df.parse(DATE2);
			if (dt1.getTime() > dt2.getTime()) {
				return 1;
			} else if (dt1.getTime() < dt2.getTime()) {
				return -1;
			} else {
				return 0;
			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return 0;
	}

	/**
	 * 
	 * TODO:验证此日期串格式是否正确
	 * 
	 * @author wangyd
	 * @date:May 24, 2012
	 * @param sourceDate
	 * @return
	 */
	public static boolean isDate(String sourceDate) {
		if (sourceDate == null) {
			return false;
		}
		try {
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
			dateFormat.setLenient(false);
			dateFormat.parse(sourceDate);
			return true;
		} catch (Exception e) {
		}
		return false;

	}

	/**
	 * 
	 * TODO:根据需要转换的日期格式，将字符串日期转换为日期对象
	 * 
	 * @param dateStr
	 *            待转换的日期
	 * @return:
	 */
	public static Date formateDateToString(String dateStr, String pattern) {
		if (dateStr == null || dateStr.equals("")) {
			return null;
		}
		try {
			if (dateStr.length() <= 10) {
				dateStr += " 00:00:00";
			}
			SimpleDateFormat formatDate = new SimpleDateFormat(pattern);
			Date returnDate = formatDate.parse(dateStr);
			return returnDate;

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 验证传入的两个date中是否date1>date2，如果date1>date2 则返回true,否则为false
	 */
	public static int compareDate(Date date1, Date date2) {
		if (date1 == null || date2 == null) {
			return -1;
		}
		long chazhi = date1.getTime() - date2.getTime();
		if (chazhi > 0) {
			return 1;
		} else if (chazhi == 0) {
			return 0;
		}
		return -1;
	}

	/**
	 * 
	 * TODO:根据日期获取该日期的月份
	 * 
	 * @param dateStr
	 *            待转换的日期
	 * @return:
	 */
	public static int getMonthFromDateStr(String dateStr) {

		// 转换为日期类型
		Date dateTemp = formateDateToString(dateStr);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTemp);
		return calendar.get(Calendar.MONTH) + 1;
	}

	/**
	 * 
	 * TODO:根据日期获取该日期的天
	 * 
	 * @param dateStr
	 *            待转换的日期
	 * @return:
	 */
	public static int getDayFromDateStr(String dateStr) {
		// 转换为日期类型
		Date dateTemp = formateDateToString(dateStr);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTemp);
		return calendar.get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * 
	 * TODO:根据日期获取该日期的前一天
	 * 
	 * @param dateStr
	 *            待转换的日期
	 * @return:前一天日期
	 */
	public static Date getLastDay(String dateStr) {
		if (dateStr == null || dateStr.equals("") || dateStr.length() < 10) {
			return null;
		}
		Date date = formateDateToString(dateStr);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - 1);
		return calendar.getTime();
	}

	/**
	 * 
	 * TODO:根据日期获取该日期的前一天
	 * 
	 * @param date
	 *            待转换的日期
	 * @return:前一天日期
	 */
	public static Date getLastDay(Date date) {
		if (date == null) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - 1);
		return calendar.getTime();
	}

	/**
	 * 
	 * TODO:根据日期以及有效期天数，获取到期的日期
	 * 
	 * @param date
	 *            待转换的日期
	 * @param dayNum
	 *            有效期天数
	 * @return:前一天日期
	 */
	public static Date getValidity(Date date, int dayNum) {
		if (date == null) {
			return null;
		}
		if (TextUtils.isEmpty(String.valueOf(dayNum)))
			return date;
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + dayNum);
		return calendar.getTime();
	}

	/**
	 * 
	 * TODO:获取两个date的相差天数
	 */
	public static int getTwodateDiff(Calendar start, Calendar end) {
		if (start == null || end == null) {
			return 0;
		}
		long diffValue = (end.getTimeInMillis() - start.getTimeInMillis()) / (24 * 60 * 60 * 1000);
		// 包含当天
		int result = 0;
		result = Long.valueOf(diffValue).intValue() + 1;

		return result;
	}

	/**
	 * 
	 * TODO:根据日期获取该日期的当前月最大天数
	 * 
	 * @param dateStr
	 *            待转换的日期
	 * @return:
	 */
	public static int getDayMaxFromDateStr(String dateStr) {
		// 转换为日期类型
		Date dateTemp = formateDateToString(dateStr);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTemp);
		return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
	}

	/**
	 * 将时间格式化为yyyy-MM-dd hh:mm:ss格式的Date对象
	 * 
	 * @param date
	 * @param pattern
	 * @return
	 */
	public static Date formateDateByPattern(Date date, String pattern) {
		return formateDateToString(formatDateToString(date, pattern));
	}

	/**
	 * 生成默认选择的小时下拉单
	 * 
	 * @param selected
	 * @return
	 */
	public static String generateHourOptions(Integer selected) {
		// 组织小时的字符串
		// 默认当前时间
		if (selected == null) {
			selected = getCurrentHour();
		}

		StringBuffer hours = new StringBuffer();
		for (int i = 0; i < 24; i++) {
			if (selected != null && i == selected)
				hours.append("<option value='").append(i).append("' selected>").append(i)
						.append("</option>");
			else
				hours.append("<option value='").append(i).append("'>").append(i)
						.append("</option>");
		}

		return hours.toString();
	}

	/**
	 * 生成默认选择的分钟下拉单
	 * 
	 * @param selected
	 * @return
	 */
	public static String generateMinOptions(Integer selected) {
		// 组织分的字符串
		// 默认当前时间
		if (selected == null) {
			selected = getCurrentMinute();
		}
		StringBuffer mins = new StringBuffer();
		for (int j = 0; j <= 60; j++) {
			if (selected != null && j == selected)
				mins.append("<option value='").append(j).append("' selected>").append(j)
						.append("</option>");
			else
				mins.append("<option value='").append(j).append("'>").append(j).append("</option>");
		}

		return mins.toString();
	}

	/**
	 * 根据日期获取星期几 TODO:
	 * 
	 * @param date
	 * @return:
	 * @date:2011-4-2 上午10:16:19
	 * @author:Dane.wang
	 */
	public static String getDayOfWeek(Date date) {
		String week = "";
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int wk = calendar.get(Calendar.DAY_OF_WEEK) - 1;
		if (wk == 0) {
			week = "Sunday";
		} else if (wk == 1) {
			week = "Monday";
		} else if (wk == 2) {
			week = "Tuesday";
		} else if (wk == 3) {
			week = "Wednesday";
		} else if (wk == 4) {
			week = "Thursday";
		} else if (wk == 5) {
			week = "Friday";
		} else if (wk == 6) {
			week = "Saturday";
		}
		return week;
	}

	/**
	 * 
	 * TODO:获取当天星期的数字0~6表示周日到周六
	 * 
	 * @author Dane.wang
	 * @date: 2012-6-21
	 * @param date
	 * @return
	 */
	public static int getWeek(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int wk = calendar.get(Calendar.DAY_OF_WEEK) - 1;
		return wk;
	}

	/**
	 * 
	 * TODO:获取本周五日期
	 * 
	 * @author Dane.wang
	 * @date: 2012-6-21
	 * @return
	 */
	public static Date thisFriday() {
		int thisWeek = getWeek(new Date());

		return getValidity(new Date(), 5 - thisWeek);
	}

	/**
	 * 
	 * TODO:获取下周一
	 * 
	 * @author Dane.wang
	 * @date: 2012-6-21
	 */
	public static Date nextMonday() {

		return getValidity(thisFriday(), 3);
	}

	/**
	 * 
	 * TODO:获取下周五
	 * 
	 * @author Dane.wang
	 * @date: 2012-6-21
	 */
	public static Date nextFriday() {

		return getValidity(thisFriday(), 7);
	}

	/**
	 * 获取当前月的第一天 TODO:
	 * 
	 * @return:
	 * @date:2011-4-7 下午02:33:15
	 * @author:Dane.wang
	 */
	public static String getFirstDayByMonth() {
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.set(Calendar.DAY_OF_MONTH, 1);
		return formatDateToString(cal.getTime(), "yyyy-MM-dd");
	}

	/**
	 * 获取当前月的最后一天 TODO:
	 * 
	 * @return:
	 * @date:2011-4-7 下午02:33:15
	 * @author:Dane.wang
	 */
	public static String getEndDayByMonth() {
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
		return formatDateToString(cal.getTime(), "yyyy-MM-dd");
	}

	/**
	 * 
	 * TODO:获取上个月的今天的前一天
	 * 
	 * @return:
	 */
	public static String getDateLastMonth() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, 1); // 得到后一天
		calendar.add(Calendar.MONTH, -1); // 得到上一个月
		return sdf.format(calendar.getTime());
	}

	/**
	 * 计算两个日期间有多少个周六周日, 一个周末=2
	 * 
	 * @param start
	 * @param end
	 * @return
	 */
	public static int getCountWeekend(Calendar start, Calendar end) {
		if (start == null || end == null)
			return 0;
		int result = 0;
		int num = getTwodateDiff(start, end);
		for (int i = 0; i < num; i++) {
			start.getTime();
			int dw = start.get(Calendar.DAY_OF_WEEK);
			if (dw == 1 || dw == 7) {// 周六周日
				result++;
			}
			start.add(Calendar.DAY_OF_YEAR, 1);
		}
		return result;
	}

	/**
	 * 返回两个日期间所有日期
	 * 
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List getTwoDaysList(String sdate, String edate) {
		List list = new ArrayList();
		String dateStart = sdate;
		String dateEnd = edate;

		SimpleDateFormat sdfStart = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sdfEnd = new SimpleDateFormat("yyyy-MM-dd");
		try {
			sdfStart.parse(dateStart);
			Calendar clStart = sdfStart.getCalendar();
			sdfEnd.parse(dateEnd);
			Calendar clEnd = sdfEnd.getCalendar();
			while (true) {
				if (clStart.before(clEnd) || clStart.equals(clEnd)) {
					list.add(sdfStart.format(clStart.getTime()));
					clStart.add(Calendar.DAY_OF_MONTH, 1);
					clStart.set(Calendar.DAY_OF_MONTH, clStart.get(Calendar.DAY_OF_MONTH));
				} else {
					break;
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return list;
	}

	// 转换字符串成日期 yyyy-MM-dd
	public static java.sql.Date getDateByStr(String str) throws ParseException {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:MM");
		return new java.sql.Date(df.parse(str).getTime());
	}

	// 转换日期成字符串yyyy-MM-dd
	public static String formatDateToStr(Date ts) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(ts);
	}

	/**
	 * 获取指定日期时间戳
	 * 
	 * @return
	 */
	public static long getMillis(int year, int month, int day) {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.YEAR, year);
		c.set(Calendar.MONTH, month);
		c.set(Calendar.DATE, day);
		// c.set(Calendar.HOUR_OF_DAY, 0);
		// c.set(Calendar.MINUTE, 0);
		// c.set(Calendar.SECOND, 0);
		long data = (c.getTimeInMillis()) / 1000;
		return data;
	}

	/**
	 * 将Long型时间戳转化为字符串"yyyy-MM-dd_hh:mm:ss"
	 * 
	 * @param millis
	 */
	public static final String getStringfromDateTime(long millis) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date curDate = new Date(millis);// 获取当前时间
        String str = formatter.format(curDate);
        String currDate=getStringfromDay(System.currentTimeMillis());
        int index=str.indexOf(currDate);
        if(index==-1){//不为今天
            String currYear=currDate.substring(0, 4);
            index=str.indexOf(currYear);
            if(index==-1){//非今年
            }else{//为今年
                str=str.substring(5, str.length());
            }
        }else{//为今天
            str =  str.substring(currDate.length() + 1, str.length());
//            long chaTime=System.currentTimeMillis()-millis;
//            long hour=60*60*1000;
//            long mini=60*1000;
//            long strHour=chaTime/hour;
//            long strMini=chaTime/mini;
//            if(strMini<60){
//                str=strMini+"分钟前";
//            }else{
//                str=strHour+"小时"+(strMini%60)+"分钟前";
//            }
        }
        return str;
    }
    public static final String getStringfromDateTimeHan(long millis) {
        SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm");
        Date curDate = new Date(millis);// 获取当前时间
        String str = formatter.format(curDate);
        String currDate=getStringfromDay(System.currentTimeMillis());
        int index=str.indexOf(currDate);
        if(index==-1){//不为今天
            String currYear=currDate.substring(0, 4);
            index=str.indexOf(currYear);
            if(index==-1){//非今年
            }else{//为今年
                str=str.substring(5, str.length());
            }
        }else{//为今天
            str = "今天 " + str.substring(currDate.length() + 1, str.length());
//            long chaTime=System.currentTimeMillis()-millis;
//            long hour=60*60*1000;
//            long mini=60*1000;
//            long strHour=chaTime/hour;
//            long strMini=chaTime/mini;
//            if(strMini<60){
//                str=strMini+"分钟前";
//            }else{
//                str=strHour+"小时"+(strMini%60)+"分钟前";
//            }
        }
        return str;
    }
	/**
	 * 将Long型时间戳转化为字符串"yyyy-MM-dd "
	 * 
	 * @param millis
	 */
	public static final String getStringfromDay(long millis) {
//		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm");
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		Date curDate = new Date(millis);// 获取当前时间
		String str = formatter.format(curDate);
		return str;
	}
    public static final String getStringfromDayHan(long millis) {
//		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
        Date curDate = new Date(millis);// 获取当前时间
        String str = formatter.format(curDate);
        return str;
    }
	public static final String getDay(long start,long end){
		long dis=end-start;
		int hourMillions=60*60*1000;
		int dayMillions=24*hourMillions;
		int result=0;
		if(dis>0){
			result= (int) (dis/(dayMillions));//大于0天
			if(result>0){
				return result+"天";
			}
			result= (int) (dis/hourMillions);
			return result+"小时";
		}
		return null;
	}
	public static final String getDisDay(long start,long end){
		String expireDay=null;
		long dis=end-start;
		double hourmil=60*60*1000;
		double daymil=24*hourmil;
		double day=0;
		if(dis>0){
			day=(dis/daymil);
			if(day<=1){//不足一天
				expireDay=String.valueOf((dis/hourmil));
				int expireIndex=expireDay.indexOf(".");
				if(expireIndex!=-1){//含有小数
					expireDay=expireDay.substring(0,expireIndex+2)+"小时";
				}else{
					expireDay=expireDay+"小时";
				}
				return expireDay;
			}else{
				expireDay=String.valueOf(day);
				int expireIndex=expireDay.indexOf(".");
				if(expireIndex!=-1){//含有小数
					expireDay=expireDay.substring(0,expireIndex+2)+"天";
				}else{
					expireDay=expireDay+"天";
				}
			}
			return expireDay;
		}else{
			return null;
		}
	}
	// -----------------------时间戳-------------------------------
	/**
	 * 将时间转换为时间戳
	 * 
	 * @param user_time
	 * @return
	 */
	public static String getTime(String user_time) {
		String re_time = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
		Date d;
		try {
			d = sdf.parse(user_time);
			long l = d.getTime();
			String str = String.valueOf(l);
			re_time = str.substring(0, 10);

		} catch (ParseException e) {
			e.printStackTrace();
		}
		return re_time;
	}

	// 将时间戳转为字符串（预订下单用）
	public static String millis2String(String cc_time) {
		String re_StrTime = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
		// 例如：cc_time=1291778220
		long lcc_time = Long.parseLong(cc_time);
		re_StrTime = sdf.format(new Date(lcc_time * 1000L));
		return re_StrTime;
	}

	public static String gettimesSjm(String user_time) {
		String re_time = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		sdf.setTimeZone(TimeZone.getTimeZone("Asia/BeiJing"));
		Date date1;
		try {
			date1 = sdf.parse(user_time);
			long datelong = date1.getTime();
			re_time = (String.valueOf(datelong)).substring(0, 9);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return re_time;
	}

	public static String gettimes(String user_time) {
		String re_time = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Date d;
		try {
			d = sdf.parse(user_time);
			long l = d.getTime();
			String str = String.valueOf(l);
			re_time = (String) str.subSequence(0, 10);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return re_time;
	}

	// 谭涛 自定义时间戳 待服务器验证
	public static String gettimeings(String user_time) {
		String re_time = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH");
		Date d;
		try {
			d = sdf.parse(user_time);
			long l = d.getTime();
			String str = String.valueOf(l);
			re_time = (String) str.subSequence(0, 10);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return re_time;
	}

	public static String getWeek(String pTime) {

		String Week = "";

		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
		try {

			c.setTime(format.parse(pTime));

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (c.get(Calendar.DAY_OF_WEEK) == 1) {
			Week += "日";
		}
		if (c.get(Calendar.DAY_OF_WEEK) == 2) {
			Week += "一";
		}
		if (c.get(Calendar.DAY_OF_WEEK) == 3) {
			Week += "二";
		}
		if (c.get(Calendar.DAY_OF_WEEK) == 4) {
			Week += "三";
		}
		if (c.get(Calendar.DAY_OF_WEEK) == 5) {
			Week += "四";
		}
		if (c.get(Calendar.DAY_OF_WEEK) == 6) {
			Week += "五";
		}
		if (c.get(Calendar.DAY_OF_WEEK) == 7) {
			Week += "六";
		}

		return Week;
	}
	/**
	 * 获取当前时间
	 * 格式为：yyyy年MM月dd日HH:mm:ss
	 * @return
	 */
	public static final String getNowStringDate() {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
		String str = formatter.format(curDate);
		String nowDate=getTodayStringDate();
		if(str.indexOf(nowDate)!=-1){
			str=str.replace(nowDate,"今天");
		}
		return str;
	}
	public static final String getTodayStringDate() {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
		String str = formatter.format(curDate);
		return str;
	}
	/**
	 * 获取当前时间
	 * 格式为：yyyy年MM月dd日HH:mm:ss
	 * @return
	 */
	public static final String getNowStringDate1() {
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
		Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
		String str = formatter.format(curDate);
		str=str.substring(0, str.length()-1)+"0";
		return str;
	}
	
	public static final String getTodayPreDate(){
		 Date date=new Date();//取时间
		 Calendar calendar = new GregorianCalendar();
		 calendar.setTime(date);
		 calendar.add(calendar.DATE,-1);//把日期往后增加一天.整数往后推,负数往前移动
		 date=calendar.getTime(); //这个时间就是日期往后推一天的结果 
		 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		 String dateString = formatter.format(date);
		 return dateString;
	}
	//------------add by sunjm---------
	public static final String getStringfromDayLong(long millis) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm");
		Date curDate = new Date(millis);// 获取当前时间
		String str = formatter.format(curDate);
		return str;
	}
	public static final String getStringfromDayDotLong(long millis) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd");
		Date curDate = new Date(millis);// 获取当前时间
		String str = formatter.format(curDate);
		return str;
	}
	/**
	 *
	 * TODO:根据日期获取该日期的前preDay天
	 * @param preDay 待转换的日期
	 * @return:前一天日期
	 */
	public static String getPreDayDay(Date date,int preDay) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + preDay);
		return formatDateToString(calendar.getTime(), "yyyy.MM.dd");
	}
}
